<?php
include "libfunc.php";
if (!empty($_SESSION['admUser']) && !empty($_SESSION['admPass'])) {
	
	$status = $_POST['status'];
	$id = $_POST['id_request'];
	
	$kon = koneksi_db();
	$sql = "select * from dtrequest_buku where id_request = '$id'";
	$q = mysql_query($sql,$kon);
	$f = mysql_fetch_array($q);
	
	if($f['status'] == $status){
		if($status == "B"){
			echo "<script language='javascript'>alert('Maaf Status Buku dalam keadaan belum tersedia')</script>";
			echo "<script language='javascript'>window.location = 'view_request.php'</script>";
		}else{
			echo "<script language='javascript'>alert('Maaf Status Buku dalam keadaan sudah tersedia')</script>";
			echo "<script language='javascript'>window.location = 'view_request.php'</script>";
		}
	}else{
		$sql2 = "update dtrequest_buku set status = '$status' where id_request='$id'";
		$q = mysql_query($sql2,$kon);
		
		if($q){
			echo "<script language='javascript'>alert('Status Buku yang direquest telah dirubah')</script>";
			echo "<script language='javascript'>window.location = 'view_request.php'</script>";
		}else{
			echo "<script language='javascript'>alert('Kegagalan pada sistem')</script>";
			echo "<script language='javascript'>window.location = 'view_request.php'</script>";
		}
	}
	
}else{
	echo "<script language='javascript'>alert('Silakan Sign In Terlebih Dahulu')</script>";
  	echo "<script language='javascript'>window.location = '../admin/'</script>";
}
?>